package com.example.springhibernate.controller;

import com.example.springhibernate.dto.Company;
import com.example.springhibernate.dto.Person;
import com.example.springhibernate.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Size;

/**
 * MyController
 *
 * @author zhouxianfeng
 * @date 2021-4-13
 */
@RestController
@RequestMapping("/my")
@Validated
public class MyController {

    @Autowired
    private TestService testService;

    @PostMapping("/test1")
    public Person test1(@RequestBody @Valid Person person) {
        return person;
    }

    @PostMapping("/test2")
    public Company test2(@RequestBody @Valid Company company) {
        return company;
    }

    @PostMapping("/test3/{dd}")
    public Company test3(@RequestBody Company company, @Size(min = 3, message = "{MyController.test3.dd.min}") @PathVariable String dd) {
        return testService.getCompany(company);
    }

    @PostMapping("/test4/{dd}")
    public Company test4(@RequestBody Company company, @Size(min = 3, message = "{MyController.test3.dd.min}") @PathVariable String dd) {
        return testService.getCompany(null);
    }


}
